<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
    <style>
        .box{
            margin-top:20px;
            margin-bottom:10px;
        }
        .required_text{
            color:red;
            padding: 8px;
        }
        .list-group-item{
            margin: 5px 30px 5px 0;
            color: #212529;
            display: inline-block;
        }
        .list-group-item>i{
            color:red;
        }
    </style>
</head>
<body>

<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <!--基础信息-->
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <h2>3、基础信息配置</h2>
                </div>
                <div class="layui-card-body">
                    <div class="box">
                        <div style="margin-left:20px;">
                            <form class="layui-form" id="basic">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">标品名称<br>（限63字）</label>
                                    <div class="layui-input-inline" style="width: 70%">
                                        <input maxlength="63" id="standardNmae" name="name" lay-verify="required" {notempty name="$info.name"}value="{$info.name}"{/notempty} placeholder="请输入名称" autocomplete="off" class="layui-input" type="text">
                                    </div>
                                </div>

                                <div class="layui-form-item layui-form-text" style="position: relative ;z-index: 98">
                                    <label class="layui-form-label">副标题<br>(30字)</label>
                                    <div class="layui-input-block" style="max-width:500px;">
                                        <textarea placeholder="请输入副标题" class="layui-textarea" id="introduce" name="introduce" maxlength="30">{notempty name="$info.introduce"}{$info.introduce}{/notempty}</textarea>
                                    </div>
                                </div>
                                <!--顶级分类-->
                                <!--<div class="layui-form-item" id="topCategory">-->
                                    <!--<label class="layui-form-label">顶级分类</label>-->
                                    <!--<div class="layui-input-inline" style="width: 400px">-->
                                        <!--<select name="topCate" id="topCate" lay-filter="topCate" lay-search>-->
                                            <!--<option value="">请选择顶级分类</option>-->
                                            <!--{notempty name="$topCate"}-->
                                            <!--{volist name="topCate" id="vo"}-->
                                            <!--<option value="{$vo.id}" {notempty name="$info.topCate"}{if $info['topCate']==$vo['id']}selected{/if}{/notempty}>{$vo.name}</option>-->
                                            <!--{/volist}-->
                                            <!--{/notempty}-->
                                        <!--</select>-->
                                    <!--</div>-->
                                <!--</div>-->
                                <!--详细分类[多选]-->
                                <div class="layui-form-item" id="firstCategory">
                                    <label class="layui-form-label">详细分类<br>[多选]</label>
                                    <div class="layui-input-inline" style="width: 400px">
                                        <select name="categorytagid" id="categorytags" lay-filter="addCategoryTags" lay-search>
                                            <option value="">请选择详细分类</option>
                                            <!--初始化-->
                                            {notempty name="$tags"}
                                            {volist name="$tags" id="cate"}
                                            <option value="{$cate.tag_id}">{$cate.tag_name}</option>
                                            {/volist}
                                            {/notmepty}
                                        </select>
                                    </div>
                                </div>
                                <!--已选详细分类-->
                                <div class="layui-form-item" >
                                    <label class="layui-form-label">已选<br>详细分类</label>
                                    <div class="layui-input-inline" style="width: 400px">
                                        <blockquote class="layui-elem-quote elem-quote-div">
                                            <div id="shared-lists" class="shared-lists">
                                                <div class="boxcont" id="boxcont">
                                                    <div id="sortTags" class="example2 schedule_div" style="padding:15px;">
                                                        {notempty name="$tagsData"}
                                                        {volist name="tagsData" id="tag"}
                                                        <span class="list-group-item list-group-{$tag.tagid}" value="{$tag.tagid}" id="{$tag.tagid}">{$tag.tag_name}<i class="layui-icon">&#x1006;</i></span>
                                                        {/volist}
                                                        {/notempty}
                                                    </div>
                                                </div>
                                            </div>
                                        </blockquote>
                                    </div>
                                </div>
                                <!--默认景点线路-->
                                <input type="hidden" name="standard_id" value="{notempty name='$info'}{$info.id}{/notempty}">

                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn layui-btn-radius" id="basic_prev">上一页</button>
                                        <button class="layui-btn layui-btn-radius" lay-submit lay-filter="basic">下一页</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script src="__PUBLIC__/drag/Sortable.js"></script>
<script>
    $('.example2').each(function () {
        new Sortable( document.getElementById("sortTags"), {
            group: 'shared',
            animation: 150,
            scroll:true,
            forceFallback: true,
            onEnd:function (evt) {
                var schedule_id = evt.to.id;
                var one1=evt.item.id
                var str = '';
                $("#"+schedule_id).find(".list-group-item").each(function(){
                    str += ","+$(this).attr("id");
                });
                console.log(evt.to.id,evt.item.id,str)
                return false;
            }
        });
    });

    $(document).on('click','.list-group-item i',function () {
        $(this).parent().remove();
    })
</script>
<script>
    layui.use(['element','layer', 'form'], function() {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form;

        //***************************************************************************
        //基础信息提交
        form.on('submit(basic)', function() {
            var standardName = $("#standardName").val();
            var introduce = $("#introduce").val();
            if(standardName==''){
                layer.msg("请补全标品名称");
                return false;
            }
            //分类标签是否已选
            var id = $("#basic input[name=standard_id]").val();
            if(id=="" || id==undefined){layer.msg('请刷新页面后重试！');return false;}
            var subCates = [];

            $.each($("#sortTags .list-group-item"),function (i,v) {
                if($(v).attr('value')!==""){
                    subCates.push($(v).attr('value'));
                }
            })
            if(subCates.length < 1){layer.msg('请选择详细分类！');return false;}
            $.ajax({
                url:"{:url('admin/standard/submitBasicData')}",
                data:{
                    id:id,
                    name:standardName,
                    introduce:introduce,
                    page_index:4,
                    subCates:subCates
                },
                type:'post',
                async: false,
                success:function(res) {
                    layer.msg(res.msg);
                    if(res.code == 1) {
                        setTimeout(function(){
                            location.href = "{:url('admin/product/setsection',['id'=>$info.id])}";
                        },1500);
                    }
                    return false;
                }
            });
            return false;
        });

        //上一页   行程数据页
        $("#basic_prev").click(function(){
            location.href = "{:url('admin/standard/process',['id'=>$info['id']])}";
            return false;
        });

        //***************************************************************************
        //首页分类标签选择
        //设置标签
//        form.on('select(topCate)',function(data){
//            var value = data.value;
//            var subCates = [];
//            $.each(topCates,function (i,v) {
//                if(v.id==value){
//                    subCates = v.subCates;return false;
//                }
//            })
//            console.log(subCates);
//            var str = '';
//            $.each(subCates,function(i,v){
//                str += "<option value='"+v.tag_id+"'>"+v.tag_name+"</option>";
//            });
//            $("#categorytags option:not(:first-child)").remove();
//            $("#categorytags").append(str);
//            $("#sortTags").children().remove();
//            form.render('select');
//        });
        //首页分类标签选择
        form.on('select(addCategoryTags)', function(data){
            //添加内容到拖拽框
            var tagId = data.value;
            var tagName = $(this).text();
            if(tagId=="" || tagId==undefined){return false;}
            //判断是否已存在
            var isExistId = false;
            $.each($("#sortTags .list-group-item"),function (i,v) {
                if($(v).attr("value")==tagId){
                    isExistId = true;layer.msg('请勿重复选择');return false;
                }
            })
            if(isExistId){return false;}
            $("#sortTags").append('<span class="list-group-item list-group-'+tagId+'" value="'+tagId+'" id="'+tagId+'">'+tagName+'<i class="layui-icon">&#x1006;</i></span>');
        });

        //***************************************************************************
        //模糊查询标签list
        var cpLock = true;
        function bindFunc(){
            //解决监听输入时中文输入法问题
            $("#tags").parent().find(".layui-select-title input").on('compositionstart', function () {
                cpLock = false;
            });
            $("#tags").parent().find(".layui-select-title input").on('compositionend', function () {
                cpLock = true;
            });
            $("#tags").parent().find(".layui-select-title input").bind('input propertychange',function(){
                var CityName = $(this).val();
                showTagList(CityName,3);
            });
            //点击时选中文本
            $("#tags").parent().find(".layui-select-title input").attr("onfocus","this.select()");
        }
        bindFunc();
        function showTagList(tagName,tagType){
            setTimeout(function(){
                if (cpLock) {
                    var html="<option value=''>请填写标签</option>";
                    $.ajax({
                        url:"{:url('admin/standard/showTagList')}",
                        data:{'tagName':tagName,tagType:tagType},
                        type:'post',
                        async: false,
                        success:function(data) {
                            console.log(data);
                            for(var i=0;i<data.length;i++){
                                html += "<option value="+data[i]["tag_id"]+">"+data[i]["tag_name"]+"</option>";
                            }
                            $("#tags").html(html);
                        }
                    });

                    //重新渲染select
                    form.render('select');
                    bindFunc();
                    bindFunc1();
                    bindFunc2();

                    $("#tags").next().addClass("layui-form-selected");
                    $("#tags").next().find(".layui-input").focus();
                    $("#tags").next().find(".layui-input").val(tagName);
                }
            },1);
        }

        //模糊查询商品list
        var cpLock1 = true;
        function bindFunc1(){
            //解决监听输入时中文输入法问题
            $("#addGoods").parent().find(".layui-select-title input").on('compositionstart', function () {
                cpLock1 = false;
            });
            $("#addGoods").parent().find(".layui-select-title input").on('compositionend', function () {
                cpLock1 = true;
            });
            $("#addGoods").parent().find(".layui-select-title input").bind('input propertychange',function(){
                var GoodsName = $(this).val();
                showGoodsList(GoodsName);
            });
            //点击时选中文本
            $("#addGoods").parent().find(".layui-select-title input").attr("onfocus","this.select()");
        }
        bindFunc1();
        function showGoodsList(GoodsName){
            setTimeout(function(){
                if (cpLock1) {
                    var html="<option value=''>请填写商品名称</option>";
                    $.ajax({
                        url:"{:url('admin/standard/showGoodsList')}",
                        data:{'GoodsName':GoodsName},
                        type:'post',
                        async: false,
                        success:function(data) {
                            console.log(data);
                            for(var i=0;i<data.length;i++){
                                html += "<option value="+data[i]["goods_id"]+">"+data[i]["goods_id"]+"__"+data[i]["goods_name"]+"</option>";
                            }
                            $("#addGoods").html(html);
                        }
                    });

                    //重新渲染select
                    form.render('select');
                    bindFunc();
                    bindFunc1();
                    bindFunc2();

                    $("#addGoods").next().addClass("layui-form-selected");
                    $("#addGoods").next().find(".layui-input").focus();
                    $("#addGoods").next().find(".layui-input").val(GoodsName);
                }
            },1);
        }

    });
</script>

</body>
</html>
